package io.kiki.stack.netty.channelManager;

import io.kiki.stack.netty.util.NamedThreadFactory;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Setter
@Getter
public class ChannelEventExecutor {

    Executor executor = new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10000), new NamedThreadFactory("-conn-event-executor", true));

    public void onEvent(Runnable runnable) {
        try {
            executor.execute(runnable);
        } catch (Throwable t) {
            log.error("Exception caught when execute channel event!", t);
        }
    }
}
